package com.sanyang.pda.presenter;

import com.sanyang.pda.bean.MoveRespose;
import com.sanyang.pda.bean.SearchStockDetailBean;
import com.sanyang.pda.contract.MovementContract;
import com.sanyang.pda.net.NetUtils;
import com.wangshen.base.net.bean.BaseAppEntity;
import com.wangshen.base.ui.mvp.base.presenter.BasePresenter;

import io.reactivex.functions.Consumer;

public class MovementPresenter extends BasePresenter<MovementContract.View> implements MovementContract.Presenter {

    @Override
    public void mobileInventoryInfo(String pallet) {
        NetUtils.geApi().mobileInventoryInfo(pallet)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<MoveRespose>>() {
                    @Override
                    public void accept(BaseAppEntity<MoveRespose> searchStockDetailBeanBaseAppEntity) throws Exception {
                        getView().setData(searchStockDetailBeanBaseAppEntity.getData());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void moveOut(String pallet, String storagebinId) {
        NetUtils.geApi().moveOut(pallet, storagebinId)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<SearchStockDetailBean>>() {
                    @Override
                    public void accept(BaseAppEntity<SearchStockDetailBean> searchStockDetailBeanBaseAppEntity) throws Exception {
                        getView().onSuccess();
                        getView().showMessage(searchStockDetailBeanBaseAppEntity.getMsg());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void moveIn(String pallet, String storagebinId) {
        NetUtils.geApi().moveIn(pallet, storagebinId)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<SearchStockDetailBean>>() {
                    @Override
                    public void accept(BaseAppEntity<SearchStockDetailBean> searchStockDetailBeanBaseAppEntity) throws Exception {
                        getView().onSuccess();
                        getView().showMessage(searchStockDetailBeanBaseAppEntity.getMsg());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }
}
